home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / phigs / ptk.lha / ptk / source / demo / menutest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-29  |  27.3 KB  |  1,020 lines

  1. /*--------------------------------------------------------------------------- 
  2.  
  3.  Program name: Menus demonstration program.
  4.  
  5.  Author: Gareth Williams
  6.  
  7.  Description: This program demonstrates box menus, user menus and rotators
  8.  and enables interaction using the pick, locator and string input devices.
  9.  
  10.  Modification history : (Version), (Date), (Name), (Description).
  11.  
  12.  1.0, 1st March 1991, G. Williams, First Version.
  13.  
  14.  2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
  15.  
  16.  SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
  17.  
  18. ----------------------------------------------------------------------------*/
  19.  
  20. #include <stdio.h>
  21. #include <math.h>
  22. #include <phigs.h>
  23. #include "ptk.h"
  24.  
  25. /* #define SUNMONO */
  26.  
  27. #define WS1     1
  28. #define NUMCPTS 19
  29. #define PI 3.14
  30.  
  31. /* Operating system dependent code, UNIX/VMS pathnames */
  32. /* UNIX pathname */
  33. #define OPENWSNAME "../scripts/openws.scr"
  34.  
  35. static char *colwrd[] = 
  36.      {
  37.          "BLACK", "GREEN", 
  38.         "MEDIUM GREEN", "MAGENTA", "MEDIUM MAGENTA", 
  39.         "WHITE", "GREY", 
  40.      };
  41.  
  42. static Pint wst;
  43. static Pint mainmenuid, inputmenuid, boxmenuid, usermenuid, userboxid;
  44. static Pint rotator1, rotator2, rotator3;
  45. static Pfloat devx, devy, devz;
  46. static Plimit3 pointecho;
  47. static Plimit3 boxport = {0.0, 0.2, 0.0, 0.2, 0.0, 0.1};
  48. static ptkboolean docolour = FALSE;
  49.  
  50. /*--------------------------------------------------------------------------*/
  51.  
  52. static void makecircle(C(Ppoint3 *) centre, C(Pfloat) radius, 
  53.                        C(Ppoint3 *) pts)
  54. PreANSI(Ppoint3 *centre)
  55. PreANSI(Pfloat radius)
  56. PreANSI(Ppoint3 *pts)
  57. {
  58.   Pfloat delta;
  59.   Pint i;
  60.  
  61.   delta = 2 * PI / NUMCPTS;
  62.   for (i = 0; i < NUMCPTS; i++) 
  63.   {
  64.     pts[i].x = centre->x + radius * cos(i * delta);
  65.     pts[i].y = centre->y + radius * sin(i * delta);
  66.     pts[i].z = centre->z;
  67.   }
  68. }
  69.  
  70. /*--------------------------------------------------------------------------*/
  71.  
  72. static void makeellipse(C(Ppoint3 *) centre, C(Pfloat) xradius, 
  73.                         C(Pfloat) yradius, C(Ppoint3 *) pts)
  74. PreANSI(Ppoint3 *centre)
  75. PreANSI(Pfloat xradius)
  76. PreANSI(Pfloat yradius)
  77. PreANSI(Ppoint3 *pts)
  78. {
  79.   Pfloat delta;
  80.   Pint i;
  81.  
  82.   delta = 2 * PI / NUMCPTS;
  83.   for (i = 0; i < NUMCPTS; i++) 
  84.   {
  85.     pts[i].x = centre->x + xradius * cos(i * delta);
  86.     pts[i].y = centre->y + yradius * sin(i * delta);
  87.     pts[i].z = centre->z;
  88.   }
  89. }
  90.  
  91. /*--------------------------------------------------------------------------*/
  92.  
  93. static void shadebox(C(Ppoint3 *) pos, C(Pfloat) height, C(Pfloat) width,
  94.                      C(Pfloat) xpercent, C(Pfloat) ypercent, 
  95.                      C(Pint) tlcol, C(Pint) brcol, C(Pint) mcol)
  96. PreANSI(Ppoint3 *pos)
  97. PreANSI(Pfloat height)
  98. PreANSI(Pfloat width)
  99. PreANSI(Pfloat xpercent)
  100. PreANSI(Pfloat ypercent)
  101. PreANSI(Pint tlcol)
  102. PreANSI(Pint brcol)
  103. PreANSI(Pint mcol)
  104. {
  105.   Ppoint3 pts[6];
  106.   Ppoint_list3 sets;
  107.  
  108.   pset_int_style(PSTYLE_SOLID);
  109.   pset_int_colr_ind(mcol);
  110.   pts[0] = ptk_point3(pos->x - (width / 2.0), pos->y - (height / 2.0), 
  111.                       pos->z);
  112.   pts[1] = ptk_point3(pts[0].x, pts[0].y + height, pos->z);
  113.   pts[2] = ptk_point3(pts[0].x + width, pts[1].y, pos->z);
  114.   pts[3] = ptk_point3(pts[2].x - (width * xpercent), 
  115.                       pts[2].y - (height * ypercent), pos->z);
  116.   pts[4] = ptk_point3(pts[1].x + (width * xpercent), pts[3].y, pos->z);
  117.   pts[5] = ptk_point3(pts[4].x, pts[0].y + (height * ypercent), pos->z);
  118.  
  119.   pts[2] = ptk_point3(pts[3].x, pts[5].y, pos->z);
  120.   sets.num_points = 4;
  121.   sets.points = &pts[2];
  122.   pfill_area3(&sets);
  123.  
  124.   pset_edge_flag(PEDGE_ON);
  125.   pset_int_colr_ind(tlcol);
  126.   pset_edge_colr_ind(tlcol);
  127.   pts[2] = ptk_point3(pts[0].x + width, pts[1].y, pos->z);
  128.   sets.num_points = 6;
  129.   sets.points = pts;
  130.   ptk_fillareaset3(1, &sets);
  131.  
  132.   pset_int_colr_ind(brcol);
  133.   pset_edge_colr_ind(brcol);
  134.   pts[1].x += width;
  135.   pts[1].y -= height;
  136.   pts[4].x = pts[3].x;
  137.   pts[4].y = pts[5].y;
  138.   ptk_fillareaset3(1, &sets);
  139. }
  140.  
  141. /*--------------------------------------------------------------------------*/
  142.  
  143. static void makeshademenu()
  144. {
  145.   Ppoint3 itemcentre, pts[20];
  146.   Pint white, black, green, i;
  147.   Ptext_align align;
  148.   Ppoint txpt, boxpt;
  149.   Pfloat charheight;
  150.   Ppoint_list3 ptlist;
  151.  
  152.   if (docolour)
  153.   {
  154.     white = ptk_stringtoint("colourindex", "white");
  155.     black = ptk_stringtoint("colourindex", "black");
  156.     green = ptk_stringtoint("colourindex", "green");
  157.   }
  158.   else
  159.   {
  160.     white = 1;
  161.     black = 0;
  162.     green = 0;
  163.   }
  164.  
  165.   ptk_openstruct(ptk_stringtoint("structureid", "shademenu1"));
  166.   itemcentre = ptk_point3(0.4, 0.7, 0.0);
  167.   shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
  168.  
  169.   /* dashed line */
  170.   pset_linewidth(3.0);
  171.   pset_linetype(PLINE_DASH);
  172.   pts[0] = ptk_point3(0.35, 0.65, 0.0);
  173.   pts[1] = ptk_point3(0.45, 0.75, 0.0);
  174.   ptlist.num_points = 2;
  175.   ptlist.points = pts;
  176.   ppolyline3(&ptlist);
  177.   ptk_closestruct();
  178.  
  179.   ptk_openstruct(ptk_stringtoint("structureid", "shademenu3"));
  180.   itemcentre.y -= 0.2;
  181.   shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
  182.  
  183.   /* circle */
  184.   makecircle(&itemcentre, 0.05, pts);
  185.   pts[19] = pts[0];
  186.   ptlist.num_points = 20;
  187.   ppolyline3(&ptlist);
  188.   ptk_closestruct();
  189.  
  190.   ptk_openstruct(ptk_stringtoint("structureid", "shademenu5"));
  191.   itemcentre.y -= 0.2;
  192.   shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
  193.  
  194.   /* ellipse */
  195.   makeellipse(&itemcentre, 0.05, 0.025, pts);
  196.   pts[19] = pts[0];
  197.   ppolyline3(&ptlist);
  198.   ptk_closestruct();
  199.  
  200.   ptk_openstruct(ptk_stringtoint("structureid", "shademenu2"));
  201.   itemcentre = ptk_point3(0.6, 0.7, 0.0);
  202.   shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
  203.  
  204.   /* polygon */
  205.   
  206.   pts[0] = ptk_point3(0.55, 0.75, 0.0);
  207.   pts[1] = ptk_point3(0.65, 0.75, 0.0);
  208.   pts[2] = ptk_point3(0.53, 0.63, 0.0);
  209.   pts[3] = ptk_point3(0.67, 0.63, 0.0);  
  210.   pts[4] = pts[0];
  211.   ptlist.num_points = 5;
  212.   ppolyline3(&ptlist);
  213.   ptk_closestruct();
  214.  
  215.   ptk_openstruct(ptk_stringtoint("structureid", "shademenu4"));
  216.   itemcentre.y -= 0.2;
  217.   shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
  218.  
  219.   pset_int_colr_ind(white);
  220.   pset_int_style(PSTYLE_HATCH);
  221.   pset_int_style_ind(-5);
  222.   for (i = 0; i < 5; i++)
  223.     pts[i].y -= 0.2;
  224.   ptlist.num_points = 4;
  225.   pfill_area3(&ptlist);
  226.   ptk_closestruct();
  227.  
  228.   ptk_openstruct(ptk_stringtoint("structureid", "shademenu6"));
  229.   itemcentre.y -= 0.2;
  230.   shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
  231.  
  232.   /* capital A */
  233.   boxpt = ptk_point(0.2 - (0.2 * 0.1), 0.2 - (0.2 * 0.1));
  234.   ptk_computecharheight(WS1, "A", &boxpt, -6, &charheight);
  235.   pset_char_ht(charheight);
  236.   pset_text_font(-6);
  237.   align.hor = PHOR_CTR;
  238.   align.vert = PVERT_HALF;
  239.   pset_text_align(&align);
  240.   txpt = ptk_point(itemcentre.x, itemcentre.y);
  241.   ptext(&txpt, "A");
  242.   ptk_closestruct();  
  243. }
  244.  
  245. /*--------------------------------------------------------------------------*/
  246.  
  247. static void highlightshadeitem(C(Pint) itemnum)
  248. PreANSI(Pint itemnum)
  249. {
  250.   Pint err, tlcol, brcol;
  251.   ptkselcontent elcont;
  252.   Pstore store;
  253.  
  254.   if (itemnum != 0)
  255.   {
  256.   switch (itemnum)
  257.   {
  258.   case 1: ptk_openstruct(ptk_stringtoint("structureid", "shademenu1"));
  259.           break;
  260.  
  261.   case 2: ptk_openstruct(ptk_stringtoint("structureid", "shademenu2"));
  262.           break;
  263.  
  264.   case 3: ptk_openstruct(ptk_stringtoint("structureid", "shademenu3"));
  265.           break;
  266.  
  267.   case 4: ptk_openstruct(ptk_stringtoint("structureid", "shademenu4"));
  268.           break;
  269.  
  270.   case 5: ptk_openstruct(ptk_stringtoint("structureid", "shademenu5"));
  271.           break;
  272.  
  273.   case 6: ptk_openstruct(ptk_stringtoint("structureid", "shademenu6"));
  274.           break;
  275.  
  276.   }
  277.   pset_elem_ptr(5);
  278.  
  279.   pcreate_store(&err, &store);
  280.   ptk_inqcurelemtypesizecontent(store, &err, &elcont);
  281.   tlcol = elcont.eldata->int_data;
  282.   pdel_store(store);
  283.   pset_elem_ptr(8);
  284.   pcreate_store(&err, &store);
  285.   ptk_inqcurelemtypesizecontent(store, &err, &elcont);
  286.   brcol = elcont.eldata->int_data;
  287.   pdel_store(store);
  288.   pset_elem_ptr(5);
  289.   ptk_seteditmode(PEDIT_REPLACE);
  290.   pset_int_colr_ind(brcol);
  291.   poffset_elem_ptr(1);
  292.   pset_edge_colr_ind(brcol);
  293.   pset_elem_ptr(8);
  294.   pset_int_colr_ind(tlcol);
  295.   poffset_elem_ptr(1);
  296.   pset_edge_colr_ind(tlcol);
  297.   ptk_unseteditmode();
  298.   ptk_closestruct();
  299.   }
  300. }
  301.  
  302. /*--------------------------------------------------------------------------*/
  303.  
  304. static void pickinput(C(Pint *) itemnum)
  305. PreANSI(Pint *itemnum)
  306. {
  307.   Pin_status status;
  308.   Ppick_path initpath;
  309.   Plimit3 pickecho;
  310.   Ppick_data3 pickrec;
  311.   Ppath_order pickorder;    
  312.   Ppick_path pickdata;
  313.   Ppick_path_elem pickarray[10];
  314.   Pint pickpet;
  315.   ptksgeneralinput pickinput;
  316.   ptksmenuoutput pickoutput;
  317.   Pint_list menuset;
  318.   Pint menusetlist[20], menunamelist[20];
  319.   Pint totsize, i, err;
  320.   Pfilter pickfilt;
  321.  
  322.   /* test picking */
  323.   *itemnum = 0;
  324.   printf("Pick a menu item...\n");
  325.   /* initialise pick */
  326. #ifdef SUN
  327.   status = PIN_STATUS_NONE;
  328. #endif
  329. #ifdef HP
  330.   status = PIN_STATUS_NO_IN;
  331. #endif
  332.   initpath.depth = 0;
  333.   pickecho.x_min = 0.0;
  334.   pickecho.y_min = 0.0;
  335.   pickecho.z_min = 0.0;
  336.   pickecho.x_max = 0.1;
  337.   pickecho.y_max = 0.1;
  338.   pickecho.z_max = 0.1;
  339.   pickorder = PORDER_BOTTOM_FIRST;
  340.   
  341.   pickfilt.excl_set.num_ints = 0;
  342.   pickfilt.incl_set.num_ints = 0;
  343.   menuset.ints = menusetlist;
  344.   pickfilt.incl_set.ints = menunamelist;
  345.   ptk_inqpostedmenus(WS1, 20, &menuset, &totsize, &err);
  346.   for (i = 0; i < totsize; i++)
  347.   {
  348.     ptk_inqmenuname(menuset.ints[i], 
  349.                  &pickfilt.incl_set.ints[pickfilt.incl_set.num_ints++], &err);
  350.   }
  351.   pset_pick_filter(1, 1, &pickfilt);
  352.  
  353. #ifdef SUN
  354.   pickpet = 2;
  355.   pickrec.pets.pet_r2.highl_colr = 2;
  356.   pickrec.pets.pet_r2.highl_count = 2;
  357.   pickrec.pets.pet_r2.highl_duration = 0.3;
  358.  
  359.   pickrec.pets.pet_r2.ap_size = 1.0;
  360.  
  361. #endif
  362. #ifdef VMS
  363.   pickpet = 1;
  364.   pickrec.pets.pet_r1.aperature = 0.05;
  365. #endif
  366. #ifdef HP
  367.   pickpet = 1;    
  368.   pickrec.pets.pet_r1.highl_colr_ind = 3;
  369.   pickrec.pets.pet_r1.x_dim = 0.005;
  370.   pickrec.pets.pet_r1.y_dim = 0.005;
  371.   pickrec.pets.pet_r1.z_dim = 2.0;
  372. #endif
  373. #ifdef PEXSI
  374.   pickpet = 1;
  375. #endif
  376.  
  377.   pinit_pick3(1, 1, status, &initpath, pickpet, &pickecho, &pickrec, 
  378.               pickorder); 
  379.  
  380.   /* set pick */
  381.   pset_pick_mode(1, 1, POP_REQ, PSWITCH_ECHO);
  382.  
  383.   /* request pick */
  384.   pickdata.path_list = pickarray;
  385.  
  386.   preq_pick(1, 1, 10, &status, &pickdata);
  387.  
  388.   if (status == PIN_STATUS_OK)
  389.   {
  390.     pickinput.inputclass = PIN_PICK;
  391.     pickinput.ptkugeninput.ptkspickinput.pickdata = pickdata;
  392.     pickinput.ptkugeninput.ptkspickinput.pathorder = PORDER_BOTTOM_FIRST;
  393.     if (ptk_scanmenus(WS1, &pickinput, &pickoutput))
  394.     {
  395.       printf("menu item %d was picked from menu %d.\n", pickoutput.itemnum, 
  396.              pickoutput.menuid);
  397.       *itemnum = pickoutput.itemnum;
  398.     }
  399.     else
  400.       printf("You did not pick a menu.\n");
  401.   }
  402.   else
  403.     printf("Nothing picked.\n");
  404. }
  405.  
  406. /*--------------------------------------------------------------------------*/
  407.  
  408. ptkboolean getmenupick(C(Pint) menuid, C(ptksmenuoutput *) pickoutput)
  409. PreANSI(Pint menuid)
  410. PreANSI(ptksmenuoutput *pickoutput)
  411. {
  412.   Pin_status status;
  413.   Ppick_path initpick;
  414.   Plimit3 pickecho;
  415.   Ppick_data3 pickrec;
  416.   Ppath_order pickorder;    
  417.   Ppick_path pickdata;
  418.   Ppick_path_elem pickarray[10];
  419.   Pint pickpet;
  420.   ptksgeneralinput pickinput;
  421.   Pint menusetlist[20];
  422.   Pint totsize;
  423.   char name[30];
  424.   Pfilter pickfilt;
  425.  
  426.   pickfilt.excl_set.num_ints = 0;
  427.   pickfilt.incl_set.num_ints = 1;
  428.   pickfilt.incl_set.ints = menusetlist;
  429.   sprintf(name, "name$menu%d", menuid);
  430.   menusetlist[0] = ptk_stringtoint("name", name);
  431.   pickecho.x_min = 0.0;
  432.   pickecho.y_min = 0.0;
  433.   pickecho.z_min = 0.0;
  434.   pickecho.x_max = 0.1;
  435.   pickecho.y_max = 0.1;
  436.   pickecho.z_max = 0.1;
  437. #ifdef SUN
  438.   status = PIN_STATUS_NONE;
  439. #endif
  440. #ifdef HP
  441.   status = PIN_STATUS_NO_IN;
  442. #endif
  443.   initpick.depth = 0;
  444.   initpick.path_list = NULL;
  445.   pickorder = PORDER_BOTTOM_FIRST;
  446.   /* make menu pickable */
  447.   pset_pick_filter(1, 1, &pickfilt);
  448.  
  449. #ifdef SUN
  450.   pickpet = 2;
  451.   pickrec.pets.pet_r2.highl_colr = 2;
  452.   pickrec.pets.pet_r2.highl_count = 2;
  453.   pickrec.pets.pet_r2.highl_duration = 0.2;
  454.  
  455.   pickrec.pets.pet_r2.ap_size = 1.0;
  456.  
  457. #endif
  458. #ifdef VMS
  459.   pickpet = 1;
  460.   pickrec.pets.pet_r1.aperature = 0.05;
  461. #endif
  462. #ifdef HP
  463.   pickpet = 1;    
  464.   pickrec.pets.pet_r1.highl_colr_ind = 3;
  465.   pickrec.pets.pet_r1.x_dim = 0.005;
  466.   pickrec.pets.pet_r1.y_dim = 0.005;
  467.   pickrec.pets.pet_r1.z_dim = 2.0;
  468. #endif
  469. #ifdef PEXSI
  470.   pickpet = 1;
  471. #endif
  472.  
  473.   pinit_pick3(1, 1, status, &initpick, pickpet, &pickecho, &pickrec, 
  474.               pickorder); 
  475.  
  476.   /* set pick */
  477.   pset_pick_mode(1, 1, POP_REQ, PSWITCH_ECHO);
  478.  
  479.   /* request pick */
  480.   pickdata.path_list = pickarray;
  481.   preq_pick(1, 1, 10, &status, &pickdata);
  482.  
  483.   if (status == PIN_STATUS_OK)
  484.   {
  485.     pickinput.inputclass = PIN_PICK;
  486.     pickinput.ptkugeninput.ptkspickinput.pickdata = pickdata;
  487.     pickinput.ptkugeninput.ptkspickinput.pathorder = PORDER_BOTTOM_FIRST;
  488.   }
  489.   return ptk_scanmenus(WS1, &pickinput, pickoutput);
  490. }
  491.  
  492. /*--------------------------------------------------------------------------*/
  493.  
  494. void pointinput(C(Pint *) itemnum)
  495. PreANSI(Pint *itemnum)
  496. {
  497.   /* test locator */
  498.   Pint initview, viewindex;
  499.   Ppoint initpt, locpos;
  500.   Pin_status status;
  501.   Plimit echovol;
  502.   Ploc_data locrec;
  503.   ptksgeneralinput locinput;
  504.   ptksmenuoutput locoutput;
  505.  
  506.   *itemnum = 0;
  507.   printf("Point at a menu item...\n");
  508.   initview = 0;
  509.   initpt = ptk_point(0.5, 0.5);
  510.   echovol.x_min = 0.0;
  511.   echovol.y_min = 0.0;
  512.   echovol.x_max = devx;
  513.   echovol.y_max = devy;
  514. #ifdef HP
  515.   locrec.pets.pet_r1.loc_colr_ind = 1;
  516. #endif
  517.   pinit_loc(1, 1, initview, &initpt, 1, &echovol, &locrec);
  518.   pset_loc_mode(1, 1, POP_REQ, PSWITCH_ECHO);
  519.   preq_loc(1, 1, &status, &viewindex, &locpos);
  520.   if (status == PIN_STATUS_OK)
  521.   locinput.inputclass = PIN_LOC;
  522.   locinput.ptkugeninput.locpoint = locpos;
  523.   if (ptk_scanmenus(WS1, &locinput, &locoutput))
  524.   {
  525.     printf("menu item %d was pointed at from menu %d.\n", locoutput.itemnum, 
  526.            locoutput.menuid);
  527.     *itemnum = locoutput.itemnum;
  528.     if (locoutput.measure)
  529.       printf("value, x = %f, y = %f\n", locoutput.value.x, 
  530.              locoutput.value.y);
  531.   }
  532.   else
  533.     printf("You did not point at a menu.\n");
  534. }
  535.  
  536. /*--------------------------------------------------------------------------*/
  537.  
  538. static void stringinput(C(Pint *) itemnum)
  539. PreANSI(Pint *itemnum)
  540. {
  541.   /* test string */
  542.   ptksgeneralinput strinput;
  543.   char dummystr[30];
  544.   Pint dummylen;
  545.   ptksmenuoutput stroutput;
  546.   Plimit echoarea;
  547.  
  548.   *itemnum = 0;
  549.   strinput.inputclass = PIN_STRING;
  550.   printf("Enter a menu item...\n");    
  551.   echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
  552.   ptk_readstring(WS1, "", "Type menu item name >", &echoarea,
  553.                  30, dummystr, &dummylen);
  554.   strncpy(strinput.ptkugeninput.str, dummystr, dummylen);
  555.   strinput.ptkugeninput.str[dummylen] = '\0';    
  556.   if (ptk_scanmenus(WS1, &strinput, &stroutput))
  557.   {
  558.     printf("menu item %d was entered from menu %d.\n", stroutput.itemnum, 
  559.            stroutput.menuid);
  560.     *itemnum = stroutput.itemnum;
  561.   }
  562.   else
  563.     printf("No menu item of that name.\n");
  564. }
  565.  
  566. /*--------------------------------------------------------------------------*/
  567.  
  568. static void makemainmenu(C(void))
  569. {
  570.   Pint i, err;
  571.   Ppoint topleft;
  572.   Ppoint box;
  573.   Pint numboxes; 
  574.   Ptext_path mpath;
  575.   Pint textind;
  576.   Pfloat charht;
  577.   Pint white, black, green;
  578.   
  579.   /* create a BOX menu */
  580.   /* set up main menu - box menu(box, user, rotator, exit) */
  581.   mainmenuid = ptk_stringtoint("menuid", "mainmenu"); 
  582.   box = ptk_point(0.2, 0.1);
  583.   textind = 1;
  584.   charht = 0.025;
  585.   topleft = ptk_point(0.8, 1.0);
  586.  
  587.   ptk_createboxmenu(mainmenuid, &topleft, &box);
  588.  
  589.   if (docolour)
  590.   {
  591.     white = ptk_stringtoint("colourindex", "white");
  592.     black = ptk_stringtoint("colourindex", "black");
  593.     green = ptk_stringtoint("colourindex", "green");
  594.     ptk_setboxmenuattrs(1, mainmenuid, PPATH_LEFT, -3, 
  595.                     white, green, green, white, black, white, green, green);
  596.   }
  597.  
  598.   ptk_createtextmenuitem(mainmenuid, "box", 1, PEDIT_INSERT, &err);
  599.   ptk_createtextmenuitem(mainmenuid, "user", 2, PEDIT_INSERT, &err);
  600.   ptk_createtextmenuitem(mainmenuid, "rotator", 3, PEDIT_INSERT, &err);
  601.   ptk_createtextmenuitem(mainmenuid, "exit", 4, PEDIT_INSERT, &err);
  602. }
  603.  
  604. /*--------------------------------------------------------------------------*/
  605.  
  606. static void makeinputmenu(C(void))
  607. /* create a box menu for selecting a PHIGS input device */
  608. {
  609.   Pint i, err;
  610.   Ppoint topleft;
  611.   Ppoint box;
  612.   Pint numboxes; 
  613.   Ptext_path mpath;
  614.   Pint white, magenta, black, darkmagenta;
  615.  
  616.   inputmenuid = ptk_stringtoint("menuid", "inputmenu"); 
  617.   box = ptk_point(0.1, 0.05);
  618.   topleft = ptk_point(0.8, 0.5);
  619.  
  620.   ptk_createboxmenu(inputmenuid, &topleft, &box);
  621.  
  622.   if (docolour)
  623.   {
  624.     white = ptk_stringtoint("colourindex", "white");
  625.     magenta = ptk_stringtoint("colourindex", "magenta");
  626.     darkmagenta = ptk_stringtoint("colourindex", "medium magenta");
  627.     black = ptk_stringtoint("colourindex", "black");
  628.     ptk_setboxmenuattrs(1, inputmenuid, PPATH_DOWN, 1, white, 
  629.      magenta, magenta, white, black, white, darkmagenta, darkmagenta);
  630.   }
  631.  
  632.   ptk_createtextmenuitem(inputmenuid, "pick", 1, PEDIT_INSERT, &err);
  633.   ptk_createtextmenuitem(inputmenuid, "point", 2, PEDIT_INSERT, &err);
  634.   ptk_createtextmenuitem(inputmenuid, "string", 3, PEDIT_INSERT, &err);
  635.   ptk_createtextmenuitem(inputmenuid, "exit", 4, PEDIT_INSERT, &err);
  636. }
  637.  
  638. /*--------------------------------------------------------------------------*/
  639.  
  640. static void createbox(C(void))
  641. /* create a box menu with 4 items */
  642. {
  643.   Pint i, err;
  644.   Ppoint topleft;
  645.   Ppoint box;
  646.   Pint numboxes; 
  647.   Ptext_path mpath;
  648.   Pint textind;
  649.   Pfloat charht;
  650.   Pint white, green, black, darkgreen;
  651.  
  652.   boxmenuid = ptk_stringtoint("menuid", "boxmenu");
  653.   box = ptk_point(0.2, 0.1);
  654.   textind = 1;
  655.   charht = 0.03;
  656.   topleft = ptk_point(0.0, 0.0);
  657.  
  658.   ptk_createboxmenu(boxmenuid, &topleft, &box);
  659.  
  660.   if (docolour)
  661.   {
  662.     white = ptk_stringtoint("colourindex", "white");
  663.     green = ptk_stringtoint("colourindex", "green");
  664.     darkgreen = ptk_stringtoint("colourindex", "medium green");
  665.     black = ptk_stringtoint("colourindex", "black");
  666.     ptk_setboxmenuattrs(1, boxmenuid, PPATH_DOWN, 1, white, green, green, 
  667.                       white, black, white, darkgreen, darkgreen);
  668.   }
  669.  
  670.   topleft = ptk_point(0.5, 0.7);
  671.   ptk_setmenuposition(boxmenuid, &topleft); 
  672.  
  673.   ptk_createtextmenuitem(boxmenuid, "item 1", 1, PEDIT_INSERT, &err);
  674.   ptk_createtextmenuitem(boxmenuid, "item 2", 2, PEDIT_INSERT, &err);
  675.   ptk_createtextmenuitem(boxmenuid, "item 3", 3, PEDIT_INSERT, &err);
  676.   ptk_createtextmenuitem(boxmenuid, "item 4", 4, PEDIT_INSERT, &err);
  677. }
  678.  
  679. /*--------------------------------------------------------------------------*/
  680.  
  681. static void createuser(C(void))
  682. /* create a user menu, 
  683. ** in this case a typical menu for a drawing package.
  684. */
  685. {
  686.   Pint userstructid;
  687.   Pint err;
  688.  
  689.   makeshademenu();
  690.   usermenuid = ptk_stringtoint("menuid", "usermenu"); 
  691.   userstructid = ptk_stringtoint("structureid", "usermenu"); 
  692.   ptk_createusermenu(usermenuid, userstructid);
  693.   ptk_createstructmenuitem(usermenuid, 
  694.         ptk_stringtoint("structureid", "shademenu1"), 1, PEDIT_INSERT, &err);
  695.   ptk_createstructmenuitem(usermenuid, 
  696.         ptk_stringtoint("structureid", "shademenu2"), 2, PEDIT_INSERT, &err);
  697.   ptk_createstructmenuitem(usermenuid, 
  698.         ptk_stringtoint("structureid", "shademenu3"), 3, PEDIT_INSERT, &err);
  699.   ptk_createstructmenuitem(usermenuid, 
  700.         ptk_stringtoint("structureid", "shademenu4"), 4, PEDIT_INSERT, &err);
  701.   ptk_createstructmenuitem(usermenuid, 
  702.         ptk_stringtoint("structureid", "shademenu5"), 5, PEDIT_INSERT, &err);
  703.   ptk_createstructmenuitem(usermenuid, 
  704.         ptk_stringtoint("structureid", "shademenu6"), 6, PEDIT_INSERT, &err);
  705. }
  706.  
  707. /*--------------------------------------------------------------------------*/
  708.  
  709. static void createrotator(C(void))
  710. /* create a 1D, 2D and 3D rotator */
  711. {
  712.   Ppoint size, pos;
  713.   Pint white, black, green;
  714.  
  715.   /* create a rotator */
  716.   rotator1 = ptk_stringtoint("menuid", "1drotator");
  717.   rotator2 = ptk_stringtoint("menuid", "2drotator");
  718.   rotator3 = ptk_stringtoint("menuid", "3drotator");
  719.   size = ptk_point(0.2, 0.2);
  720.  
  721.   ptk_createrotator(WS1, rotator1, PTKEONED, &size, "1D rotator",
  722.                     0.02);
  723.   ptk_createrotator(WS1, rotator2, PTKETWOD, &size, "2D rotator",
  724.                     0.02);
  725.   size = ptk_point(0.3, 0.2);
  726.   ptk_createrotator(WS1, rotator3, PTKETHREED, &size, "3D rotator",
  727.                     0.02);
  728.   if (docolour)
  729.   {
  730.     white = ptk_stringtoint("colourindex", "white");
  731.     black = ptk_stringtoint("colourindex", "black");
  732.     green = ptk_stringtoint("colourindex", "green");
  733.     ptk_setrotatorattrs(WS1, rotator1, 1, white, green, white, green, 
  734.                         white, green, white, black);
  735.     ptk_setrotatorattrs(WS1, rotator2, 1, white, green, white, green, 
  736.                        white, green, white, black);
  737.     ptk_setrotatorattrs(WS1, rotator3, -3, white, green, white, green,
  738.                         white, green, white, black);
  739.   }
  740.   pos = ptk_point(0.5, 0.3);
  741.   ptk_setmenuposition(rotator1, &pos);
  742.   pos = ptk_point(0.5, 0.55);
  743.   ptk_setmenuposition(rotator2, &pos);
  744.   pos = ptk_point(0.5, 0.8);
  745.   ptk_setmenuposition(rotator3, &pos);
  746.   ptk_setrotatortitle(rotator1, "zoom"); 
  747. }
  748.  
  749. /*--------------------------------------------------------------------------*/
  750.  
  751. static void testboxmenu(C(void))
  752. /* enable pick, locator and string input on box menus, 
  753. ** Menu items on the input menu and box menu are highlighted
  754. ** when selected.
  755. */
  756. {
  757.   ptkboolean boxmenuquit;
  758.   ptksmenuoutput output;
  759.   Pint itemnum, err;
  760.  
  761.   ptk_unpostmenu(WS1, mainmenuid);  
  762.   ptk_postmenu(WS1, inputmenuid);
  763.  
  764.   ptk_postmenu(WS1, boxmenuid);  
  765.   ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
  766.   boxmenuquit = FALSE;
  767.   do
  768.   {
  769.     output.itemnum = 0;
  770.     if (getmenupick(inputmenuid, &output))
  771.     {
  772.       ptk_setboxmenuhighlightitem(inputmenuid, output.itemnum);
  773.       ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
  774.       switch (output.itemnum)
  775.       {
  776.         case 1: pickinput(&itemnum);
  777.                 ptk_setboxmenuhighlightitem(boxmenuid, itemnum);
  778.                 break;
  779.         case 2: pointinput(&itemnum);
  780.                 ptk_setboxmenuhighlightitem(boxmenuid, itemnum);
  781.                 break;
  782.         case 3: stringinput(&itemnum);
  783.                 ptk_setboxmenuhighlightitem(boxmenuid, itemnum);
  784.                 break;
  785.         case 4: boxmenuquit = TRUE;
  786.                 break;  
  787.       }
  788.       ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
  789.     }
  790.   } while (!boxmenuquit);
  791.   ptk_clearboxmenuhighlight(inputmenuid);
  792.   ptk_clearboxmenuhighlight(boxmenuid);
  793.   ptk_unpostmenu(WS1, boxmenuid);
  794. }
  795.  
  796. /*--------------------------------------------------------------------------*/
  797.  
  798. static void testusermenu(C(void))
  799. /* enable pick, locator and string input on user menu.
  800. ** The invisibility filter is used to hide the main menu.
  801. */
  802. {
  803.   ptkboolean usermenuquit;
  804.   ptksmenuoutput output;
  805.   Pint err, itemnum, lastitemnum, stid, invismenu;
  806.   char name[20];
  807.   Pfilter invisfilt;
  808.  
  809.   invisfilt.excl_set.num_ints = 0;
  810.   invisfilt.excl_set.ints = NULL;
  811.   invisfilt.incl_set.num_ints = 1;
  812.   invisfilt.incl_set.ints = &invismenu;
  813.   lastitemnum = itemnum = 0;
  814.  
  815.   sprintf(name, "name$menu%d", mainmenuid);
  816.   invismenu = ptk_stringtoint("name", name);
  817.   pset_invis_filter(WS1, &invisfilt);
  818.   ptk_postmenu(WS1, inputmenuid);
  819.  
  820.   ptk_postmenu(WS1, usermenuid);  
  821.   ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
  822.   usermenuquit = FALSE;
  823.   do
  824.   {
  825.     output.itemnum = 0;
  826.     if (getmenupick(inputmenuid, &output))
  827.     {
  828.       switch (output.itemnum)
  829.       {
  830.         case 1: pickinput(&itemnum);
  831.                 break;
  832.         case 2: pointinput(&itemnum);
  833.                 break;
  834.         case 3: stringinput(&itemnum);
  835.                 break;
  836.         case 4: usermenuquit = TRUE;
  837.                 break;  
  838.       }
  839.       highlightshadeitem(lastitemnum);      
  840.       highlightshadeitem(itemnum);
  841.       lastitemnum = itemnum;
  842.       ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
  843.     }
  844.   } while (!usermenuquit);
  845.   highlightshadeitem(lastitemnum);   
  846.   invisfilt.incl_set.num_ints = 0;   
  847.   pset_invis_filter(WS1, &invisfilt);
  848.   ptk_unpostmenu(WS1, usermenuid);
  849. }
  850.  
  851. /*--------------------------------------------------------------------------*/
  852.  
  853. static void testrotator(C(void))
  854. /* enable pick and locator input on rotators */
  855. {
  856.   ptkboolean rotatorquit;
  857.   ptksmenuoutput output;
  858.   Pint err, itemnum;
  859.  
  860.   ptk_delmenuitem(inputmenuid, 3);
  861.   ptk_unpostmenu(WS1, mainmenuid);  
  862.   ptk_postmenu(WS1, inputmenuid);
  863.   
  864.   ptk_postmenu(WS1, rotator1);
  865.   ptk_postmenu(WS1, rotator2);
  866.   ptk_postmenu(WS1, rotator3);
  867.   ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
  868.   rotatorquit = FALSE;
  869.   do
  870.   {
  871.     output.itemnum = 0;
  872.     if (getmenupick(inputmenuid, &output))
  873.     switch (output.itemnum)
  874.     {
  875.       case 1: pickinput(&itemnum);
  876.               break;
  877.       case 2: pointinput(&itemnum);
  878.               break;
  879.       case 3: rotatorquit = TRUE;
  880.               break;  
  881.     }
  882.   } while (!rotatorquit);
  883.   ptk_unpostmenu(WS1, rotator1);
  884.   ptk_unpostmenu(WS1, rotator2);
  885.   ptk_unpostmenu(WS1, rotator3);
  886.   ptk_createtextmenuitem(inputmenuid, "string", 3, PEDIT_INSERT, &err);
  887. }
  888.  
  889. /*--------------------------------------------------------------------------*/
  890.  
  891. main()
  892. {
  893.   Pedit_mode mode;
  894.   Pint err;
  895.   Pint_bundle rotintrep, boxintrep;
  896.   Ptext_bundle textrep;
  897.   Pedge_bundle rotedgerep, boxedgerep;
  898.   ptkboolean menuquit;
  899.   ptksmenuoutput output;
  900.   Pws_st_tables lens;
  901.  
  902.   /* open PHIGS */
  903.   printf("Demonstrating the menus utility of the PHIGS Toolkit...\n");
  904.  
  905.   /* Implementation dependent code, open PHIGS and workstation */
  906. #ifdef SUN
  907.   printf("Opening SunPHIGS...\n");
  908.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  909.  
  910.   /* open the workstation */
  911.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  912. #endif
  913. #ifdef PEXSI
  914.   printf("Opening PEX-SI PHIGS...\n");
  915.   popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
  916.  
  917.   /* open the workstation */
  918.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  919. #endif
  920. #ifdef HP
  921.   printf("Opening HP PHIGS...\n");
  922.   popen_phigs(stderr, PDEF_MEM_SIZE);
  923.  
  924.   /* open the workstation */
  925.   ptk_readphinterscript(OPENWSNAME, NULL, NULL);    
  926. #endif
  927.   
  928.   pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
  929.  
  930.   /* set up required hashtables */  
  931.   ptk_inithashtables();
  932.   ptk_createhashtable("structureid", 0, 100);
  933.   ptk_createhashtable("viewindex", 1, 100);
  934.   ptk_createhashtable("label", 0, 100);
  935.   ptk_createhashtable("colourindex", 1, 100);
  936.   ptk_createhashtable("name", 1, 100);
  937.   ptk_createhashtable("menuid", 1, 100);
  938.  
  939.   ptk_inqmaxdevicecoords(WS1, &devx, &devy);
  940.   devz = 0.0;
  941.   pointecho.x_min = pointecho.y_min = pointecho.z_min = 0.0;
  942.   pointecho.x_max = devx;
  943.   pointecho.y_max = devy;
  944.   pointecho.z_max = devz;
  945.  
  946. #ifdef VMS
  947.   pinq_ws_st_table(wst, &err, &lens);
  948.   if (lens.colr > 9)
  949.     docolour = TRUE;
  950. #endif
  951. #ifdef SUN
  952. #ifndef SUNMONO
  953.   docolour = TRUE;
  954. #endif
  955. #endif
  956. #ifdef HP
  957. #ifndef HPMONO
  958.   docolour = TRUE;
  959. #endif
  960. #endif
  961. #ifdef PEXSI
  962. #ifndef PEXSIMONO
  963.   docolour = TRUE;
  964. #endif
  965. #endif
  966.  
  967.   /* set colours */
  968.   if (docolour)
  969.   {
  970.     ptk_setupcolourtable(WS1, 7, colwrd);
  971.     ptk_setbackgroundcolourind(WS1, ptk_stringtoint("colourindex", "grey"));
  972.   }
  973.  
  974.   /* menus to select type of menu and type of input */
  975.   
  976.   makemainmenu();
  977.  
  978.   makeinputmenu();
  979.  
  980.   /* create box, user and rotator menus */
  981.  
  982.   createbox();
  983.  
  984.   createuser();
  985.  
  986.   createrotator();
  987.  
  988.   /* interaction loop */
  989.   menuquit = FALSE;
  990.   do
  991.   {
  992.     ptk_postmenu(WS1, mainmenuid);
  993.     ptk_unpostmenu(WS1, inputmenuid);    
  994.     pupd_ws(WS1, PFLAG_PERFORM);
  995.     ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
  996.     output.itemnum = 0;
  997.     if (getmenupick(mainmenuid, &output))
  998.     switch (output.itemnum)
  999.     {
  1000.       case 1: testboxmenu();
  1001.               break;
  1002.       case 2: testusermenu();
  1003.               break;
  1004.       case 3: testrotator();
  1005.               break;
  1006.       case 4: menuquit = TRUE;
  1007.               break;  
  1008.     }
  1009.   } while (!menuquit);
  1010.  
  1011.   pclose_ws(WS1);
  1012.   printf("Closing PHIGS...\n");
  1013.   pclose_phigs();
  1014.   exit(0);
  1015. }
  1016.  
  1017. /*--------------------------------------------------------------------------*/
  1018.  
  1019. /* end of menutest.c */
  1020.